function add(...args) {
  return args.reduce((a, b) => a + b, 0);
}

function curry(fn) {
  let args = [];
  return function temp(...newArgs) {
    if (newArgs.length) {
      args = [...args, ...newArgs];
      return temp;
    } else {
      const val = fn.apply(this, args);
      args = [];
      return val;
    }
  };
}

const curried = curry(add);
console.log(curried(1)(2)(3)());
console.log(curried());
